#this allows for multiplications in the .html
from django import template

register = template.Library()

def multWithScalar(leftHandSide, rightHandSide):
        floatl=0
        if leftHandSide!="" :
                floatl = float(leftHandSide)
        floatr=0
        if rightHandSide!="" :
                floatr = float(rightHandSide)
        return floatl * floatr

def toStringWithDigits(floatValue, numberOfDigits):
        floatValue0 = 0
        if( floatValue!="" ):
                floatValue0 = float(floatValue)
        if( numberOfDigits == "0" ):
                return '%10.0f' %floatValue0
        if( numberOfDigits == "1" ):
                return '%10.1f' %floatValue0
        if( numberOfDigits == "2" ):
                return '%10.2f' %floatValue0
        if( numberOfDigits == "3" ):
                return '%10.3f' %floatValue0
        if( numberOfDigits == "4" ):
                return '%10.4f' %floatValue0
        return floatValue

register.filter('toStringWithDigits', toStringWithDigits)

register.filter('multWithScalar', multWithScalar)

